package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.TDamageListGoods;
import com.atguigu.jxc.entity.TOverflowListGoods;
import com.atguigu.jxc.service.OverflowListGoodsService;
import com.atguigu.jxc.service.OverflowListService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class OverflowController {

    @Autowired
    OverflowListService overflowListService;

    @Autowired
    OverflowListGoodsService overflowListGoodsService;


    /**
     * 请求URL：http://localhost:8080/overflowListGoods/save?overflowNumber=BY1605767033015（报溢单号）
     * 请求参数：OverflowList overflowList, String overflowListGoodsStr
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：ServiceVO
     */
    @PostMapping("/overflowListGoods/save")
    public ServiceVO save(OverflowList overflowList, String overflowListGoodsStr){

        return overflowListService.save(overflowList,overflowListGoodsStr);
    }






    /**
     * 请求URL：http://localhost:8080/overflowListGoods/list
     * 请求参数：String  sTime（开始时间）, String  eTime（结束时间）
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */

    @PostMapping("/overflowListGoods/list")
    public Map<String,Object> list(String  sTime, String  eTime){
        Map<String,Object> result = new HashMap<>();

        List<OverflowList> list = overflowListService.list(sTime,eTime);
        result.put("rows",list);

        return result;
    }

    /**
     * 请求URL：http://localhost:8080/overflowListGoods/goodsList
     * 请求参数：Integer overflowListId
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */

    @PostMapping("/overflowListGoods/goodsList")
    public Map<String,Object> findOverflowListGoods(Integer overflowListId){

        QueryWrapper<TOverflowListGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("overflow_list_id",overflowListId);

        List<TOverflowListGoods> list = overflowListGoodsService.list(wrapper);
        Map<String, Object> result = new HashMap<>();
        result.put("rows",list);

        return result;
    }

}
